import { MockMethod } from 'vite-plugin-mock';
import Mock from 'mockjs';

// 小红书笔记模型
// interface XhsNote {
//   user_id: string;
//   nickname: string;
//   avatar: string;
//   ip_location: string;
//   add_ts: number;
//   last_modify_ts: number;
//   note_id: string;
//   type: string;
//   title: string;
//   desc: string;
//   video_url: string;
//   time: number;
//   last_update_time: number;
//   liked_count: string;
//   collected_count: string;
//   comment_count: string;
//   share_count: string;
//   image_list: string;
//   tag_list: string;
//   note_url: string;
// }

// // 小红书评论模型
// interface XhsNoteComment {
//   user_id: string;
//   nickname: string;
//   avatar: string;
//   ip_location: string;
//   add_ts: number;
//   last_modify_ts: number;
//   comment_id: string;
//   create_time: number;
//   note_id: string;
//   content: string;
//   sub_comment_count: number;
//   pictures: string;
// }

export default [
  // 获取采购列表接口（现有）
  {
    url: '/api/get-purchase-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|1-100': [
            {
              index: /S20201228115950[0-9][0-9][0-9]/,
              pdName: 'Macbook',
              pdNum: 'p_tmp_60a637cd0d',
              'purchaseNum|1-100': 100,
              adminName: '财务部111',
              updateTime: '2020-05-20@date("HH:mm:ss")',
              pdType: '电子产品',
            },
            {
              index: /S20201228115950[0-9][0-9][0-9]/,
              pdName: 'Macbook',
              pdNum: 'p_tmp_60a637cd0d',
              'purchaseNum|1-100': 100,
              adminName: '财务部',
              updateTime: '2020-05-20@date("HH:mm:ss")',
            },
          ],
        }),
      },
    }),
  },
  {
    url: '/api/get-list',
    method: 'get',
    response: (options) => {
      const { platform } = options.query;
      if (platform === 'xhs') {
        // 返回符合 XhsNote 模型的数据
        return {
          code: 0,
          data: {
            ...Mock.mock({
              'list|1-50': [
                {
                  'index|+1': 1,
                  user_id: '@guid',
                  nickname: '@cname',
                  avatar: '@image("100x100", "#50B347", "Avatar")',
                  ip_location: '@city()',
                  add_ts: '@integer(1609459200, 1612137600)', // 时间戳
                  last_modify_ts: '@integer(1609459200, 1612137600)',
                  note_id: '@guid',
                  type: '@pick(["normal", "video"])',
                  title: '@title(5, 10)',
                  desc: '@sentence(10, 20)',
                  video_url: '@url',
                  time: '@integer(1609459200, 1612137600)',
                  last_update_time: '@integer(1609459200, 1612137600)',
                  'liked_count|0-1000': 0,
                  'collected_count|0-500': 0,
                  'comment_count|0-300': 0,
                  'share_count|0-200': 0,
                  image_list: '@image("200x200", "#FF6600", "Image")',
                  tag_list: '@word(3, 5)',
                  note_url: '@url',
                },
              ],
            }),
          },
        };
      }

      // 其他平台的模拟数据（可根据需要扩展）
      return {
        code: 0,
        data: {
          ...Mock.mock({
            'list|1-50': [
              {
                'index|+1': 1,
                status: '@natural(0, 4)',
                no: `BH00${Mock.Random.natural(1, 100).toString().padStart(2, '0')}`,
                name: '@city()办公用品采购项目',
                'paymentType|1': '@natural(0, 1)',
                'contractType|1': '@natural(0, 2)',
                updateTime: `2020-05-30 ${Mock.Random.time('HH:mm:ss')}`,
                amount: Mock.Random.float(10, 500000000, 0, 2),
                adminName: '@cname',
              },
            ],
          }),
        },
      };
    },
  },
  // 获取小红书笔记详情接口
  {
    url: '/api/get-note-detail',
    method: 'get',
    response: (options) => {
      const { note_id } = options.query;

      return {
        code: 0,
        data: {
          ...Mock.mock({
            user_id: '@guid',
            nickname: '@cname',
            avatar: '@image("100x100", "#50B347", "Avatar")',
            ip_location: '@city()',
            add_ts: '@integer(1609459200, 1612137600)',
            last_modify_ts: '@integer(1609459200, 1612137600)',
            note_id: note_id || '@guid',
            type: '@pick(["normal", "video"])',
            title: '@title(5, 10)',
            desc: '@sentence(10, 20)',
            video_url: '@url',
            time: '@integer(1609459200, 1612137600)',
            last_update_time: '@integer(1609459200, 1612137600)',
            liked_count: '@natural(0, 1000)',
            collected_count: '@natural(0, 500)',
            comment_count: '@natural(0, 300)',
            share_count: '@natural(0, 200)',
            image_list: '@image("200x200", "#FF6600", "Image")',
            tag_list: '@word(3, 5)',
            note_url: '@url',
            // 关联评论
            comments: {
              'list|0-10': [
                {
                  'comment_id|+1': 1,
                  user_id: '@guid',
                  nickname: '@cname',
                  avatar: '@image("50x50", "#4A7EBB", "Commenter")',
                  ip_location: '@city()',
                  add_ts: '@integer(1609459200, 1612137600)',
                  last_modify_ts: '@integer(1609459200, 1612137600)',
                  create_time: '@integer(1609459200, 1612137600)',
                  note_id: note_id || '@guid',
                  content: '@sentence(5, 15)',
                  'sub_comment_count|0-5': 0,
                  pictures: '@image("100x100", "#A2D9CE", "Picture")',
                },
              ],
            },
          }),
        },
      };
    },
  },
  // 其他接口（保持不变或根据需要调整）
  {
    url: '/api/detail-basic',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          name: 'td_20023747',
          loginType: 'Web',
          currentRole: 'Admin',
          rightsList: '通用权限',
          userStatus: '启用',
          language: '简体中文',
          timeZone: '(GMT+08:00)中国时区—北京（Asia/Beijing）',
        }),
      },
    }),
  },
  {
    url: '/api/get-card-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|48-50': [
            {
              'index|+1': 1,
              isSetup: '@boolean',
              'type|1': '@natural(1, 5)',
              'banner|1': [
                'https://tdesign.gtimg.com/starter/cloud-db.jpg',
                'https://tdesign.gtimg.com/starter/cloud-server.jpg',
                'https://tdesign.gtimg.com/starter/ssl.jpg',
                'https://tdesign.gtimg.com/starter/t-sec.jpg',
                'https://tdesign.gtimg.com/starter/face-recognition.jpg',
              ],
              'name|1': ['人脸识别', 'SSL证书', 'CVM', '云数据库', 'T-Sec 云防火墙'],
              'description|1': [
                '基于腾讯优图强大的面部分析技术，提供包括人脸检测与分析、五官定位、人脸搜索、人脸比对、人脸',
                '云硬盘为您提供用于CVM的持久性数据块级存储服务。云硬盘中的数据自动地可用区内以多副本冗',
                'SSL证书又叫服务器证书，腾讯云为您提供证书的一站式服务，包括免费、付费证书的申请、管理及部',
                '腾讯安全云防火墙产品，是腾讯云安全团队结合云原生的优势，自主研发的SaaS化防火墙产品，无需客无需客无需客无需客无需客无需客无需客',
                '云数据库MySQL为用户提供安全可靠，性能卓越、易于维护的企业级云数据库服务。',
              ],
            },
          ],
        }),
      },
    }),
  },
  {
    url: '/api/get-project-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|1-50': [
            {
              'index|+1': 1,
              adminPhone: '+86 13587609955',
              updateTime: '2020-05-30 @date("HH:mm:ss")',
              'adminName|1': ['顾娟	', '常刚', '郑洋'],
              'name|1': [
                '沧州市办公用品采购项目',
                '红河哈尼族彝族自治州办公用品采购项目	',
                '铜川市办公用品采购项目',
                '陇南市办公用品采购项目	',
                '六安市办公用品采购项目	 ',
              ],
            },
          ],
        }),
      },
    }),
  },
  {
    url: '/api/post',
    method: 'post',
    response: (options) => {
      const body = JSON.parse(options.body);
      return {
        code: 0,
        message: '提交成功',
        data: {
          ...body,
          index: Mock.mock('@increment'),
          status: 1, // 假设提交后状态为"进行中"
          updateTime: Mock.mock('@now("yyyy-MM-dd HH:mm:ss")'),
          comment: Mock.mock('@natural(0, 500)'),
          subComment: Mock.mock('@natural(0, 200)'),
          op: '操作',
        },
      };
    },
  },

  // 获取爬虫列表接口，用于mounted时加载数据
  {
    url: '/api/get-crawler-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|1-50': [
            {
              'index|+1': 1,
              platform: '@pick(["小红书", "抖音", "哔哩哔哩", "微博", "快手", "百度贴吧", "知乎"])',
              type: '@pick(["关键词搜索", "帖子详情", "创作者主页数据"])',
              keywords: '@word(5, 10)',
              comment: '@boolean',
              subComment: '@boolean',
              remark: '@sentence(5, 10)',
              'status|1': '@natural(1, 3)',
              createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              startTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              endTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              op: '操作',
            },
          ],
        }),
      },
    }),
  },

  // 获取爬虫列表接口，用于mounted时加载数据
  {
    url: '/api/get-crawler-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|1-50': [
            {
              'index|+1': 1,
              platform: '@pick(["小红书", "抖音", "哔哩哔哩", "微博", "快手", "百度贴吧", "知乎"])',
              type: '@pick(["关键词搜索", "帖子详情", "创作者主页数据"])',
              keywords: '@word(5, 10)',
              comment: '@boolean',
              subComment: '@boolean',
              remark: '@sentence(5, 10)',
              'status|1': '@natural(1, 3)',
              createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              startTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              endTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              op: '操作',
            },
          ],
        }),
      },
    }),
  },

  // 获取爬虫列表接口，用于mounted时加载数据
  {
    url: '/api/get-crawler-list',
    method: 'get',
    response: () => ({
      code: 0,
      data: {
        ...Mock.mock({
          'list|1-50': [
            {
              'index|+1': 1,
              platform: '@pick(["小红书", "抖音", "哔哩哔哩", "微博", "快手", "百度贴吧", "知乎"])',
              type: '@pick(["关键词搜索", "帖子详情", "创作者主页数据"])',
              keywords: '@word(5, 10)',
              comment: '@boolean',
              subComment: '@boolean',
              remark: '@sentence(5, 10)',
              'status|1': '@natural(1, 3)',
              createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              startTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              endTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
              op: '操作',
            },
          ],
        }),
      },
    }),
  },
  // 启动爬虫接口
  {
    url: '/api/start-crawler',
    method: 'post',
    response: () => {
      // 模拟处理过程，随机返回成功或失败
      const isSuccess = Mock.Random.boolean();
      if (isSuccess) {
        return {
          code: 0,
          message: '启动成功',
        };
      }
      return {
        code: 1,
        message: '启动失败',
      };
    },
  },
  // 爬虫状态查询接口
  {
    url: '/api/get-crawler-status',
    method: 'get',
    response: () => {
      // 模拟不同的状态返回
      // 状态1：进行中，状态2：完成，状态3：失败
      const status = Mock.Random.integer(1, 3);
      let message = '';
      switch (status) {
      case 1:
        message = '爬虫运行中';
        break;
      case 2:
        message = '爬虫已完成';
        break;
      case 3:
        message = '爬虫运行失败';
        break;
      default:
        message = '未知状态';
      }
      return {
        code: 0,
        message,
        data: {
          status,
        },
      };
    },
  },
] as MockMethod[];
